package edu.xidian.bdilab.jrbigdata.service.bank.demandcheck.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.xidian.bdilab.jrbigdata.controller.bank.BankCode;
import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.domain.EnterpriseReq;
import edu.xidian.bdilab.jrbigdata.mapper.EnterpriseReqMapper;
import edu.xidian.bdilab.jrbigdata.service.bank.demandcheck.DemandCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;

@Service
public class DemandCheckServiceImpl implements DemandCheckService {
    @Autowired
    EnterpriseReqMapper enterpriseMapper;
    @Override
    public ResponseResult demandcheck(Integer loanLimit, Double lowerLimit, Double upperLimit, Integer loanPeriod, Integer guaranteeMode)
    {
        QueryWrapper<EnterpriseReq> enterprise_reqWrapper = new QueryWrapper<>();
        ResponseResult responseResult=new ResponseResult();
        enterprise_reqWrapper.eq(loanLimit!=null,"loan_limit",loanLimit);
        enterprise_reqWrapper.eq(loanPeriod!=null,"loan_period",loanPeriod);
        enterprise_reqWrapper.eq(guaranteeMode!=null,"guarantee_mode",guaranteeMode);
        enterprise_reqWrapper.ge(lowerLimit!=null,"rate_lower_limit",lowerLimit);
        enterprise_reqWrapper.le(upperLimit!=null,"rate_upper_limit",upperLimit);
        enterprise_reqWrapper.eq("is_public",0);
        List<EnterpriseReq>list=enterpriseMapper.selectList(enterprise_reqWrapper);
        responseResult.setCode(BankCode.CHENCK_FAILED.getCode());
        responseResult.setMessage(BankCode.CHENCK_FAILED.getMessage());
        responseResult.setSuccess(FALSE);
        if(list.size()==0)
        {
            responseResult.setCode(BankCode.CHECK_NONE.getCode());
            responseResult.setMessage(BankCode.CHECK_NONE.getMessage());
            responseResult.setSuccess(FALSE);
        }


        else
        {
            responseResult.setData(list);
            responseResult.setCode(BankCode.CHECK_SUCCESS.getCode());
            responseResult.setMessage(BankCode.CHECK_SUCCESS.getMessage());
            responseResult.setSuccess(TRUE);

        }

        return  responseResult;
    }
}
